package com.focusai.efairy.model.request;

import com.focusai.efairy.model.manager.CacheManager;
import com.focusai.efairy.model.response.DeviceCompanycodeListResponse;
import com.focusai.efairy.network.Response;
import com.focusai.efairy.network.exception.ParseException;
import com.focusai.efairy.network.request.base.Request;
import com.focusai.efairy.network.utils.UrlUtils;
import com.focusai.efairy.utils.GsonHelper;
import com.google.gson.reflect.TypeToken;

import org.json.JSONException;

import java.util.Map;

/**
 *
 * 获取企业代码列表
 * Created by lifeng on 2018/7/2.
 */

public class GetDeviceCompanyCodeListRequest extends Request<DeviceCompanycodeListResponse> {

    private String lastId;

    public GetDeviceCompanyCodeListRequest(String last_id,Response.Listener<DeviceCompanycodeListResponse> listener) {
        super(Method.GET, UrlUtils.createUrl("/appapi/device_companycode_list"), listener);
        this.lastId = last_id;
    }


    @Override
    public Map<String, String> getParams() throws JSONException {
        addParam("efairyuser_id", CacheManager.getUserId());//设备编号
        addParam("access_token", CacheManager.getAccessToken());//令牌
        addParam("last_id", lastId);
        addParam("size", "20");

        return super.getParams();
    }

    @Override
    protected DeviceCompanycodeListResponse parse(String result) throws ParseException {
        return GsonHelper.getInstance().fromJson(result, new TypeToken<DeviceCompanycodeListResponse>() {
        }.getType());
    }

}
